home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-10-23 | 4.0 KB | 128 lines | [TEXT/MWPS] |
- {
- { MyAlerts.p
- {
- { Pascal version by Bill Catambay
- { Original C version by Kenneth Worley
- { Public Domain
- {
- {
- { Routines that make it easier to show a quick error or
- { informational dialog.
- }
- Unit MyAlerts;
-
- Interface
-
- Uses
- Types, Dialogs, TextUtils, Resources, QDOffscreen;
-
- Procedure DoAlert(DialogID: integer; playAlert: boolean);
- Procedure DoAlertStrID(dialogID: integer; playAlert: boolean;
- errStrID: integer);
- Procedure DoAlertStrIndexID(dialogID: integer; playAlert: boolean;
- errStrID, index: integer);
- Procedure DoAlertStr(dialogID: integer; playAlert: boolean;
- errString: str255);
-
- Implementation
-
- Procedure DoAlert(DialogID: integer; playAlert: boolean);
- {
- This routine calls DoAlertStr with an empty error string. It is
- expected that the dialog ID you specify is a dialog that already
- has appropriate error text in it.
- }
- begin
- DoAlertStr(dialogID, playAlert, '');
- end;
-
- Procedure DoAlertStrID(dialogID: integer; playAlert: boolean;
- errStrID: integer);
- {
- This routine loads the 'STR ' resource with ID errStrID and sends
- the string and other parameters on to DoAlertStr.
- }
- Var
- errString: StringHandle;
-
- begin
- errString := GetString(errStrID);
- HLock(Handle(errString));
- DoAlertStr(dialogID, playAlert, errString^^);
- HUnlock(Handle(errString));
- ReleaseResource(Handle(errString));
- end;
-
- Procedure DoAlertStrIndexID(dialogID: integer; playAlert: boolean;
- errStrID, index: integer);
- {
- This routine loads the string in the 'STR#' resource at the index
- specified and passes the string and other parameters to the
- DoAlertStr routine.
- }
- Var
- errString: Str255;
-
- begin
- GetIndString( errString, errStrID, index );
- DoAlertStr( dialogID, playAlert, errString );
- end;
-
- Procedure DoAlertStr(dialogID: integer; playAlert: boolean;
- errString: str255);
- {
- This routine displays an alert whose resource ID number is specified
- in the parameter dialogID. The dialog specified is expected to have
- at least one button (usually labeled "OK") which will be the default
- button and have an ID if 1. When the user presses this button, the
- alert will be dismissed. The dialog should also have a static text
- item with an ID of 2. If the string in errString is not zero length,
- that string is displayed in the static text field. If the string
- is zero length, nothing is done with the text in the dialog.
- }
- Var
- currentPort: CGrafPtr; { store the current port here }
- currentDev: GDHandle; { store current device here }
- theDlg: DialogPtr; { to store our dialog in }
- itemType: integer; { these 3 local variables are used to }
- itemHandle: Handle; { manipulate items in the dialog. }
- itemRect: Rect;
- itemHit: integer; { use with ModalDialog }
-
- begin
- { Save the current grafPort }
- GetGWorld( currentPort, currentDev );
- { Now, load our dialog resource. }
- theDlg := GetNewDialog( dialogID, NIL, WindowPtr(-1) );
- { make the dialog the current port }
- SetGWorld(CGrafPtr(theDlg), NIL );
- { if the parameter specifies, do a system beep }
- if playAlert then
- SysBeep( 3 );
- { If a string was sent, put that string in the dialog. }
- if errString <> '' then
- begin
- GetDialogItem( theDlg, 2, itemType, itemHandle, itemRect );
- SetDialogItemText( itemHandle, errString );
- end;
- { now make sure the dialog is visible }
- ShowWindow( theDlg );
- { Get the OK button item and draw a bold border around it to show that
- { it's the default button. }
- GetDialogItem( theDlg, 1, itemType, itemHandle, itemRect );
- InsetRect( itemRect, -4, -4 );
- PenSize( 3, 3 );
- FrameRoundRect( itemRect, 16, 16 );
- PenSize( 1, 1 );
- { Loop and call ModalDialog until the user presses the OK button
- { This routine requires that whatever alert is shown, the button with
- { id number kAlertOKButton is the one that should dismiss the dialog. }
- ModalDialog( NIL, itemHit );
- while itemHit <> 1 do
- ModalDialog( NIL, itemHit );
- { Now get rid of the dialog and set the port back to the control panel }
- DisposeDialog( theDlg );
- SetGWorld( currentPort, currentDev );
- end;
-
- End.